package cn.xyhelp.shop.order.dao.config;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;

/**
 * @author violetfreesia
 * @since 2022-02-15
 */
public class P6SpyLogger implements MessageFormattingStrategy {
    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category,
                                String prepared, String sql, String url) {
        StringBuilder log = new StringBuilder();
        return StringUtils.isNotBlank(sql) ? log.append("【").append(now).append("】").append("本次执行时间: ")
                .append(elapsed).append("ms").append("\n执行的SQL语句: ").append(sql.replaceAll("[\\s]+", " "))
                .toString()
                : "";
    }
}
